/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package etherblocks.game;

import com.jme3.math.Vector3f;
import etherblocks.engine.states.PlayerAppState;
import etherblocks.game.entitysystem.*;
import etherblocks.game.entitysystem.components.*;
import com.cubes.BlockTerrainControl;
import pathfinding.CollisionManager;
import pathfinding.collisionshapes.*;

/**
 *
 * @author Carl
 */
public class World{

    public World(){
        
    }
    private WorldInformation worldInformation;
    private BlockTerrainControl blockTerrain;
    private EntityMap entityMap = new EntityMap();
    
    public boolean isBlockCollidingWithPlayers(int x, int y, int z){
        float blockSize = blockTerrain.getSettings().getBlockSize();
        Vector3f blockCenteredWorldLocation = new Vector3f(x, y, z).addLocal(0.5f, 0.5f, 0.5f).multLocal(blockSize);
        for(Entity entity : entityMap.getEntities(BlockSetCollisionComponent.class)){
            Vector3f location = entity.getComponent(LocationComponent.class).getLocation();
            if(CollisionManager.isColliding(new RectangleCollisionShape(blockCenteredWorldLocation.getX(), blockCenteredWorldLocation.getZ(), blockSize, blockSize), new CircleCollisionShape(location.getX(), location.getZ(), ((PlayerAppState.HITBOX.getX() * blockSize) / 2)))
            && CollisionManager.isColliding(new RectangleCollisionShape(0, blockCenteredWorldLocation.getY(), 1, blockSize), new RectangleCollisionShape(0, (location.getY() + ((PlayerAppState.HITBOX.getY() / 2) * blockSize)), 1, (PlayerAppState.HITBOX.getY() * blockSize)))){
                return true;
            }
        }
        return false;
    }

    public WorldInformation getWorldInformation(){
        return worldInformation;
    }

    public void setWorldInformation(WorldInformation worldInformation){
        this.worldInformation = worldInformation;
    }

    public BlockTerrainControl getBlockTerrain(){
        return blockTerrain;
    }

    public void setBlockTerrain(BlockTerrainControl blockTerrain){
        this.blockTerrain = blockTerrain;
    }

    public EntityMap getEntityMap(){
        return entityMap;
    }

    public void setEntityMap(EntityMap entityMap){
        this.entityMap = entityMap;
    }
}
